package com.ericsson.middleware.utils;

import com.fasterxml.jackson.databind.ObjectMapper;


public class JsonUtil {
   private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

   private JsonUtil() {
   }

   public static String toJson(Object obj) {
      try {
         return obj == null ? null : OBJECT_MAPPER.writeValueAsString(obj);
      } catch(Exception e) {
         throw new RuntimeException(e);
      }
   }

   public static Object fromJson(String json, Class objClass) {
      try {
         return OBJECT_MAPPER.readValue(json, objClass);
      } catch(Exception e) {
         throw new RuntimeException(e);
      }
   }
}